package com.thf.util;

public class ResultJson<T> {
    private Integer code;
    private String msg;
    private T obj;


    private ResultJson(ResultCode code, String msg, T obj) {
        this.code = code.getCode();
        this.msg = msg;
        this.obj = obj;
    }

    public static <T> ResultJson<T> getInstance(ResultCode code, String msg, T obj){
        return new ResultJson<T>(code,msg,obj);
    }

    public ResultJson(String msg, T obj) {
        this.msg = msg;
        this.obj = obj;
    }

    public static <T> ResultJson<T> success(String msg, T obj){
        return getInstance(ResultCode.SUCCESS,msg,obj);
    }
    public static <T> ResultJson<T> success(T obj){
        return getInstance(ResultCode.SUCCESS,"",obj);
    }
    public static <T> ResultJson<T> error(String msg, T obj){
        return getInstance(ResultCode.ERROR,msg,obj);
    }
    public static <T> ResultJson<T> error(String msg){
        return getInstance(ResultCode.ERROR,msg,null);
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getObj() {
        return obj;
    }
}
